<?php

class Admin_ContactController extends Zend_Controller_Action
{
    
    protected $_model;
    
    public function init()
    {
        /* Initialize action controller here */
        $this->_model = new Application_Model_DbTable_Contact();
       
    }

    public function indexAction()
    {
        // action body
    }
    
    public function listAction()
    {
        // action body
         $sortby = $this->_request->getParam("sortby",null);
         $sorttype = $this->_request->getParam("sorttype", "asc");
         $filter_field = $this->_request->getParam("filter_field", null);
         $filter_value = $this->_request->getParam("filter_value");
         $this->view->sort = array("by"=>$sortby, "type"=>$sorttype);
         
         $filter = null;
         if(!empty($filter_field))
         {
            $filter[$filter_field] = $filter_value;
         }
         $adapter = $this->_model->fetchPaginatorAdapter($filter,$sortby,$sorttype);
         $paginator = new Zend_Paginator($adapter);
         
         //Show 10 dòng trên 1 trang
         $paginator->setItemCountPerPage(10);
         $page = $this->_request->getParam("page",1);
         $paginator->setCurrentPageNumber($page);
         $this->view->datas = $paginator;
        $this->_helper->layout()->disableLayout();
        $this->_response->clearBody();
    }
    
    public function viewAction()
    {
        // action body
        $id = $this->_request->getParam("id");
        $row = $this->_model->find($id)->current();
        $date = new Zend_Date($row->date);
        $row->date = $date->toString("dd/MM/yyyy");
        $datas = $row->toArray();
        $intro = unserialize($row->intro);
        $datas["email"] = $intro["email"];
        
        foreach($datas as $key=>$data){
            if(empty($data)){
                $datas[$key] = "";
            }
        }
        $this->_helper->json->sendJson($datas);
    }
    
    public function delAction()
    {
        $id = $this->_request->getParam("id",null);
        $result = null;
        if($id!=null)
        {
            $row = $this->_model->find($id)->current();
            $result = $row->delete();
        }
        $this->_helper->json->sendJson($result);
    }

}













